package com.olah.project.service;

import com.olah.common.entity.po.project.Project;
import com.olah.common.entity.po.project.ProjectTag;
import com.olah.project.dao.ProjectDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProjectDaoService {

    @Resource
    private ProjectDao dao;

    public List<Project> queryAll() {
        return dao.queryAll();
    }

    public List<String> getPositions() {
        return dao.getPositions();
    }

    public void publish(Project project) {
        dao.publish(project);
        insertProjectMember(project.getId(), project.getPositions());
    }

    public void insertProjectMember(int projectId, List<ProjectTag> tags) {
        Map<String, Object> map = new HashMap<>();
        tags.forEach(tag -> {
            map.clear();
            map.put("project", projectId);
            map.put("tag", tag.getTag());
            dao.insertProjectMember(map);
        });
    }

    public Project queryById(int id) {
        return dao.queryById(id);
    }
}
